using System;
using System.IO;
using System.Diagnostics;
using System.Reflection;
using Calibur;

namespace EggWorld.Protocol
{
//	public class Hello
//	{
//		static Type unityDebug;
//		
//		static Hello ()
//		{
//			unityDebug = null;
//			FileStream fs = new FileStream ("d:\\1.txt", FileMode.OpenOrCreate);
//			StreamWriter sw = new StreamWriter (fs);
//			foreach (var ass in System.AppDomain.CurrentDomain.GetAssemblies()) {
//				if (ass.GetName().Name.Equals("UnityEngine")) {
//					foreach (var t in ass.GetTypes()) {
//						if (t.Name.Equals ("Debug")) {
//							sw.WriteLine (ass.GetName().Name + " -> " + t.Name);
//							unityDebug = t;
//						}
//					}
//				}
//			}
//			sw.Close ();
//		}
//		
//		public static void SayHello() {
//			if (unityDebug != null) {
//				unityDebug.InvokeMember("Log", 
//					BindingFlags.Default | BindingFlags.InvokeMethod, 
//					null, null, new object[] {"Are You OK!"});
//			}
//		}
//		
//	}
	
	

	public class ObjectFactory : MessageBeanFactory
	{
		public override bool NeedZip (int cmdId)
		{
			switch (cmdId) {
			case -2000:
			case 2000:
				return true;
			
			default:
				return false;
			}
		}
		
		public override Type GetMessageBeanType (int cmdId)
		{
			switch (cmdId) {
			case -2000:
				return typeof(AllType);
			case -1002:
				return typeof(LogoutResponse);
			case -1000:
				return typeof(LoginResponse);
			case 1000:
				return typeof(Login);
			case 1001:
				return typeof(Walk);
			case 1002:
				return typeof(NullMessageBean);
			case 2000:
				return typeof(AllType);
			default:
				throw new ArgumentException ("Undefined command ID and message bean class map:" + cmdId);
			}
		}
	}
}

